package com.yuwei.notice

import androidx.recyclerview.widget.LinearLayoutManager
import com.alibaba.android.arouter.facade.annotation.Route
import com.tencent.mmkv.MMKV
import com.yuwei.base.BaseFragment
import com.yuwei.base.path.RouterPath
import com.yuwei.notice.adapter.NoticeAdapter
import com.yuwei.notice.databinding.FragmentNoticeBinding
import com.yuwei.notice.viewmodel.NoticeViewModel

@Route(path = RouterPath.MODULE_NOTICE_FRAGMENT)
class NoticeFragment : BaseFragment<FragmentNoticeBinding, NoticeViewModel>() {
    val noticeAdapter = NoticeAdapter()
    override fun initView() {
        viewModel.getNotice(MMKV.defaultMMKV().decodeInt("userId"))
        binding.noticeRv.adapter = noticeAdapter
        binding.noticeRv.layoutManager = LinearLayoutManager(requireContext())
    }
    override fun initData() {
        viewModel.getNoticeSuccess.observe(this){
            noticeAdapter.data.addAll(it)
            noticeAdapter.notifyDataSetChanged()
        }
    }
}